package cn.com.lyj6851.common.validate.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.com.lyj6851.common.validate.code.ValidateCodeGenerator;
import cn.com.lyj6851.common.validate.image.ImageValidateCodeGenerator;
import cn.com.lyj6851.common.validate.sms.DefaultSmsCodeSender;
import cn.com.lyj6851.common.validate.sms.SmsCodeSender;


/**
 * 验证码配置类
 * @author Administrator
 *
 */
@Configuration
public class ValidateCodeBeanConfig {

	/**
    * 当不存在imageValidateCodeGenerator的bean时，用以下配置
    * 注:如果Spring容器中有两个接口ValidateCodeGenerator.class的实现的话,只要其中一个注入到容器;另一个不起效;
    * @return
    * @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    */
   @Bean
   @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
   public ValidateCodeGenerator imageValidateCodeGenerator() {
       ImageValidateCodeGenerator imageCodeGenerator = new ImageValidateCodeGenerator();
       //imageCodeGenerator.setSecurityProperties(securityProperties);
       return imageCodeGenerator;
   }

   /**
    *  短信验证码发送方法
    * @return
    */
   @Bean
   @ConditionalOnMissingBean(SmsCodeSender.class)
   public SmsCodeSender smsCodeSender(){
       return new DefaultSmsCodeSender();
   }
}
